

import axios from "axios";
import {useRoute} from "vue-router";

const api = axios.create({
  baseURL:'http://localhost:8090/api-boss',
  timeout: 60000
});

class DriverService{
  private router = useRoute();


//查所有
  async getAllDriver(page) {
    try {
      const response = await api.get(`/driver/getAll`,{params:{current:page.pageNum,size:page.pageSize}});
      console.log("第一步拿到的司机数据",response.data.data.records);
      return response.data.data.records;

    } catch (error) {
      console.error('查询失败', error);
      throw error;
    }
  }


  //修改司机
  async updateDriver(driverUser: any) {
    try {
      const response = await api.put(`/driver/update`,driverUser);
      return response.data;
    }catch (error){
      console.error('修改失败',error);
      throw error;
    }
  }

  //增加司机
  async addDriver(driverUser: any){
    try {
      const respone = await api.post(`/driver/add`,driverUser)
      return respone.data;
    }catch (error){
      console.error('增加失败',error);
      throw error;
    }
  }

  //条件查询司机
  async findDriver(apiBossDriver: any){
    try {
      console.log("请求参数————",apiBossDriver);
      const respone = await api.post(`/driver/find`,apiBossDriver);
      console.log('查询结果',respone.data.data.records);

      return respone.data.data.records
    }catch (error){
      console.error('查询失败',error);
      throw error;
    }
  }

  //绑定汽车
  async bindingCar(driverCarBindingRelationship: any){
    try {
      const respone = await api.post(`/driver/binding`,driverCarBindingRelationship);
      return respone.data;
    }catch(error){
      console.error('绑定失败',error);
      throw error;
    }
  }


  //解绑汽车
  async unbindCar(driverCarBindingRelationship: any){
    try {
      const respone = await api.post(`/driver/unbind`,driverCarBindingRelationship);
      return respone.data;
    }catch(error){
      console.error('解绑失败',error);
      throw error;
    }
  }
}

export const driverService = new DriverService();
